if (FALSE) {
### Save code in a file "demo.r" and run with 2 processors by
### SHELL> mpiexec -np 2 Rscript demo.r
spmd.code <- "
### Initialize
suppressMessages(library(pbdMPI, quietly = TRUE))
if(comm.size() != 2){
comm.cat(\"2 processors are requried.\n\", quiet = TRUE)
finalize()
}
### Examples.
a <- 1:(comm.rank() + 1)
b <- comm.range(a)
comm.print(b)
b <- comm.max(a)
comm.print(b)
b <- comm.min(a)
comm.print(b)
### Finish.
finalize()
"
# execmpi(spmd.code, nranks = 2L)
}
Run the code above in your browser using DataLab